<?php
	require_once 'common.inc.php';
	function getcontent($file)
	{
		$content=fopen($file,"r");
		while(!feof($content))
		{
			$str=fgets($content);
		}
		fclose($content);
		return $str;
	}

	function rewrite($filename,$type,$oldstr="",$newstr="")
	{	
	
		
		$content=getcontent("file.txt");
		if($type=="read") 
			return $content;
		elseif($type=="delete")
		{
			$oldstr.="|";
			$str=str_replace($oldstr,"",$content);
			
		}
		elseif($type=="edit")
		{
			$str=str_replace($oldstr,$newstr,$content);
			
			
		}
		elseif($type=="add")
		{
			$str=$content.$oldstr."|";
		}
		$f=fopen($filename,"w+");
		fwrite($f,$str);
		return $str;
		
	}
	
	$arr=explode("|",rewrite("file.txt","read"));
		
	//	print_r($arr);

	if($action=="delete")
	{	
		rewrite("file.txt","delete",$ip);
		
		$url="setback.php";
		echo "<script language='javascript'>";
		echo " location.href='{$url}';";
		echo "</script>";
		//header("Location:setback.php");
	}
	elseif($action=="add")
	{
		include_once 'templates/msystem/add.htm';
	}
	elseif($action=="edit")
	{	
		$va=$_GET['ip'];
		include_once 'templates/msystem/edit.htm';
	}
	else
	{
		include_once 'templates/msystem/tralist1.htm';
	}
	if($do=="add")
	{
		rewrite("file.txt","add",$ip,"");
		$url="setback.php";
		echo "<script language='javascript'>";
		echo " location.href='{$url}';";
		echo "</script>";
		//header("Location:setback.php");
	}
	elseif($do=="edit")
	{
		rewrite("file.txt","edit",$oldip,$ip);
		$url="setback.php";
		echo "<script language='javascript'>";
		echo " location.href='{$url}';";
		echo "</script>";
		//header("Location:setback.php");
	}
	
?>

